# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

_name=sphinx-autoapi
pkgname=python-sphinx-autoapi
pkgver=2.1.0
pkgrel=2
pkgdesc="A new approach to API documentation in Sphinx."
arch=(any)
url="https://github.com/readthedocs/sphinx-autoapi"
license=(MIT)
depends=(python-astroid python-jinja python-sphinx python-unidecode
python-pyyaml)
makedepends=(python-build python-installer python-setuptools python-wheel)
checkdepends=(python-pytest)
# TODO: package python-go and python-dotnet
# optdepends=(python-go python-dotnet)
source=("https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz")
sha256sums=('5b5c58064214d5a846c9c81d23f00990a64654b9bca10213231db54a241bc50f')
b2sums=('3148c01d87a42930bc5cd89569cc58c081aeaf018bc78809ab9134492c42508549d123588bca4333f67c42f130d78ede0747d7754f1e6111473d4a87ad372e80')

build() {
  cd $_name-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$site_packages:$PYTHONPATH"
  pytest -v
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {CHANGELOG,README}.rst -t "${pkgdir}/usr/share/doc/${pkgname}"

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/sphinx_autoapi-$pkgver.dist-info/LICENSE.rst "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.rst
}
